<template>
<div class="photoinfo-container">
  <h3>{{imgsinfo.title}}</h3>
  <p class="subtitle">
    <span>发表时间:{{imgsinfo.add_time | dateFormat}}</span>
    <span>点击次数:{{imgsinfo.click}}次</span>
  </p>
  <hr>
  <!-- 缩略图区域 -->
  <img class="preview-img" v-for="(item, index) in imgs" :key="item.src" :src="item.src" height="100" @click="$preview.open(index, imgs)">

  <!-- 图片内容区域 -->
  <div class="content" v-html="imgsinfo.content"></div>

  <!-- 评论子组件区域 -->
  <img-comments :id="this.$route.params.id"></img-comments>
  </div>
</template>

<script>
import comments from "../subcomponents/comment.vue";
import {Toast} from "mint-ui";
export default {
  data(){
    return {
      imgsinfo:[],
      id:this.$route.params.id,
      imgs:[]
    };
  },
  created(){
    this.getPhotoInfo();
    this.getimgs();
  },
  methods:{
    getPhotoInfo(){
      this.$http.get("api/getimageInfo/"+this.id).then(res=>{
        if(res.body.status===0){
          this.imgsinfo=res.body.message[0];
          console.log(this.imgsinfo);
        }
      })
    },
    getimgs(){
      this.$http.get("api/getthumimages/"+this.id).then(res=>{
        if(res.body.status===0){
          res.body.message.forEach(item => {
            item.w=600;
            item.h=400;
          });
          this.imgs=res.body.message;
        }else{
          Toast("获取缩略图失败~");
        }
      });
    }
  },
  components:{
    "img-comments":comments
  }
}
</script>

<style lang="scss" scoped>
.photoinfo-container {
  padding: 3px;
  h3 {
    color: #26a2ff;
    font-size: 15px;
    text-align: center;
    margin: 15px 0;
  }
  .subtitle {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
  }

  .content {
    font-size: 13px;
    line-height: 30px;
  }

  .thumbs{
    img{
      margin: 10px;
      box-shadow: 0 0 8px #999;
    }
  }
  img{
    margin:10px;
  }
}
</style>
